@extends('admin.layouts.app')
@section('product','active')


@section('content')

<div id="picbox" style="display:none;position:fixed;right:130px;top:130px;width:;height:300px;z-index:99999;background:#999"></div>
	
	 <div class="container-fluid">
            <div class="block-header">
                
                             <a href="{{route('product.index')}}/#{{$product->id}}" title="返回" class="btn-link"  >
                                        <i class="material-icons">keyboard_backspace</i> 
                                </a>
            </div>
            <!-- Basic Table -->
            <div class="row clearfix">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="card">
                        <div class="header"> 

                           <h2>
                               {{$product->pro_name}} - 货品管理 ({{$nums->sum('product_number')}})
                           </h2>
                           <div class="pull-right">
                               @if(!empty($product->type->type_name)) <span>所属类型 / {{$product->type->type_name}}</span> @endif
                           </div>
                        </div>

                        <div class="body table-bordered">
                           
                            @if($attrs)
                            

                      <form action="{{ route('product.number.store',$product->id) }}" method="post">

                            {{csrf_field()}}
                            <table class="table table-bordered table-striped table-hover js-basic-example dataTable">
                                <thead>
                                    @foreach($attrs as $key=>$attr)
                                        <th>{{$attr[0]['attr_name']}}</th>
                                    @endforeach
                                    <th>库存</th>
                                    <th>操作</th>
                                </thead>
                                <tbody>
                                    @if(!$nums->isEmpty())
                                    @foreach($nums->toArray() as $k0=>$v0)
                                    <?php 
                                        if($k0 == 0){
                                            $opt = '+';
                                        }else{
                                            $opt = '-';
                                        }
                                    ?>
                                    <tr> 
                                      
                                        @foreach($attrs as $k1=>$v1 )
                                           <td> 
                                               <select name="product_attr_id[]" style="width: 100%" class="center-block form-control">
                                                    <option value="">请选择</option>

                                                    @foreach($v1 as $k=>$v)
                                                        <option 
                                                            @if(strpos(','.$v0['product_attr_id'].',',','.$v['id'].',') !== false) 
                                                                selected 
                                                            @else 

                                                            @endif value="{{$v['id']}}">{{$v['attr_value']}}</option>
                                                    @endforeach
                                               </select>
                                           </td>
                                        @endforeach
                                        <td>
                                             <input type="text" name="product_number[]" style="border-bottom: 1px solid #eee;" value="{{$v0['product_number']}}" class="form-control" placeholder="库存">
                                        </td>
                                        <td>
                                                <a href="javascript:void(0)" onclick="clonea(this)" class="pull-left btn btn-info">{{$opt}}</a> 
                                        </td>
                                    </tr> 
                                    @endforeach
                                    @else
                                        <tr> 
                                          
                                            @foreach($attrs as $k1=>$v1 )
                                               <td> 
                                                   <select name="product_attr_id[]" style="width: 100%" class="center-block form-control">
                                                        <option value="">请选择</option>

                                                        @foreach($v1 as $k=>$v)
                                                            <option value="{{$v['id']}}">{{$v['attr_value']}}</option>
                                                        @endforeach
                                                   </select>
                                               </td>
                                            @endforeach
                                            <td>
                                                 <input type="text" name="product_number[]" style="border-bottom: 1px solid #eee;" value="" class="form-control" placeholder="库存">
                                            </td>
                                            <td>
                                                    <a href="javascript:void(0)" onclick="clonea(this)" class="pull-left btn btn-info">+</a> 
                                            </td>
                                        </tr> 
                                    @endif
                                </tbody>
                            </table>
                            
                                <button type="submit" id="addNum" class=" btn btn-primary">保存</button>
                            </form>
                            @else
                                <i class="material-icons center-block text-center" style="font-size: 150px;">error_outline</i>
                                <span class="center-block text-center">
                                这个商品没有属性..请设置默认商品库存
                                    
                                </span>
                            @endif 
                        </div>
                    </div>
                </div>
            </div>
            <!-- #END# Basic Table -->
     </div>


@endsection

@section('js-script')
	{{-- expr --}}
    <!-- JQuery DataTable Css -->
    <link href="{{ asset('admin/plugins/jquery-datatable/skin/bootstrap/css/dataTables.bootstrap.css') }}" rel="stylesheet">

	<!-- Jquery Core Js -->
    <script src="{{ asset('admin/plugins/jquery/jquery.min.js') }}"></script>
    <script>  
       
        function clonea(a)
        {
            //获取顶级
            var div = $(a).parent().parent();
            if($(a).html() == '+')
           {
            var newDiv = div.clone();
            newDiv.find("a").html("-");
            div.after(newDiv);
           }
           else
            div.remove();
        }
    </script>

    <!-- Bootstrap Core Js -->
    <script src="{{ asset('admin/plugins/bootstrap/js/bootstrap.js') }}"></script>

    <!-- Select Plugin Js -->

    <!-- Slimscroll Plugin Js -->
    <script src="{{ asset('admin/plugins/jquery-slimscroll/jquery.slimscroll.js') }}"></script>

    <!-- Waves Effect Plugin Js -->
    <script src="{{ asset('admin/plugins/node-waves/waves.js') }}"></script>

   <!-- Jquery DataTable Plugin Js -->
    <script src="{{ asset('admin/plugins/jquery-datatable/jquery.dataTables.js') }}"></script>
    <script src="{{ asset('admin/plugins/jquery-datatable/skin/bootstrap/js/dataTables.bootstrap.js') }}"></script>
    <script src="{{ asset('admin/plugins/jquery-datatable/extensions/export/dataTables.buttons.min.js') }}"></script>
    <script src="{{ asset('admin/plugins/jquery-datatable/extensions/export/buttons.flash.min.js') }}"></script>
    <script src="{{ asset('admin/plugins/jquery-datatable/extensions/export/jszip.min.js') }}"></script>
    <script src="{{ asset('admin/plugins/jquery-datatable/extensions/export/pdfmake.min.js') }}"></script>
    <script src="{{ asset('admin/plugins/jquery-datatable/extensions/export/vfs_fonts.js') }}"></script>
    <script src="{{ asset('admin/plugins/jquery-datatable/extensions/export/buttons.html5.min.js') }}"></script>
    <script src="{{ asset('admin/plugins/jquery-datatable/extensions/export/buttons.print.min.js') }}"></script>

    <!-- Custom Js -->
    <script src="{{ asset('admin/js/admin.js') }}"></script>

    {{-- <script src="{{ asset('admin/js/pages/tables/jquery-datatable.js')}}"></script> --}}
    <script type="text/javascript">
         $('.js-basic-example').DataTable({
          
        responsive: true,
        searching:false,
        language: {
        "sProcessing": "处理中...",
        "sLengthMenu": "显示 _MENU_ 项结果",
        "sZeroRecords": "没有匹配结果",
        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
        "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
        "sInfoPostFix": "",
        "sSearch": "搜索:",
        "sUrl": "",
        "sEmptyTable": "表中数据为空",
        "sLoadingRecords": "载入中...",
        "sInfoThousands": ",",
        "oPaginate": {
            "sFirst": "首页",
            "sPrevious": "上页",
            "sNext": "下页",
            "sLast": "末页"
        },
        "oAria": {
            "sSortAscending": ": 以升序排列此列",
            "sSortDescending": ": 以降序排列此列"
        }
    }

    });
    </script>
    <script src="{{ asset('admin/js/pages/ui/tooltips-popovers.js')}}"></script>

    <!-- Demo Js -->
    <script src="{{ asset('admin/js/demo.js') }}"></script> 
   
@endsection